package pl.edu.agh.gameserv.server.test;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;

import pl.edu.agh.gameserv.server.test.helper.User;

public class NoWinnerGameIT {
	ServerImplService service;
	String result[][] = { { "0", "0", "1" }, { "1", "1", "0" }, { "0", "0", "1" } };

	@Test
	public void noWinnerGame() throws Exception {
		service = new ServerImplService();
		ServerImpl server = service.getServerImplPort();

		User user1 = new User("Bolek", server);
		user1.joinGame();

		User user2 = new User("Lolek", server);
		user2.joinGame();

		user1.makeMove("00");
		user2.makeMove("20");
		user1.makeMove("21");
		user2.makeMove("01");
		user1.makeMove("12");
		user2.makeMove("11");
		user1.makeMove("10");
		user2.makeMove("22");
		user1.makeMove("02");

		assertEquals(GameStatus.FINISHED, user1.getState());
		assertEquals(GameStatus.FINISHED, user2.getState());
		assertEquals("Tie", user1.getScore());

		List<StringArray> situation = user1.getSituation();
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				assertEquals(result[j][i], situation.get(i).getItem().get(j));
	}
}